package com.taoye.thread;

public class Demo15 {
	public static void main(String[] args) throws InterruptedException {
		Demo15User u = new Demo15User();
		
		System.out.println("修改前user:" + u);
		Thread a = new Thread(()->{
			u.setName("A线程设置的名字");
			Thread.currentThread().suspend();
			u.setPwd("A线程设置的密码");
		});
		a.setName("A");
		a.start();
		Thread.sleep(10);
		System.out.println("A线程修改后user:" + u);
		
		Thread b = new Thread(()->{
			//假装B线程要等待A的业务逻辑做完后执行的代码，结果A线程挂起了导致业务未执行完，下面的逻辑永远都不会成立
			if(u.getPwd().equals("A线程设置的密码")) {
				u.setName("B线程设置的名字");
				u.setPwd("B线程设置的密码");
			}
		});
		b.setName("B");
		b.start();
		Thread.sleep(10);
		System.out.println("B线程修改后user:" + u);
	}
}

class Demo15User {
	private String name = "a";
	private String pwd = "aa";

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	@Override
	public String toString() {
		return "User [name=" + name + ", pwd=" + pwd + "]";
	}
}
